#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Car {
    int d, v, a;
} car[N];
int T, n, m, l, v, p[N];
int main() {
#ifndef Local
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
#endif
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%d%d", &n, &m, &l, &v);
        for (int i = 1; i <= n; i++)scanf("%d%d%d", &car[i].d, &car[i].v, &car[i].a);
        int l = INT_MAX, r = INT_MIN;
        for (int i = 1; i <= m; i++) {
            scanf("%d", p + i);
            l = min(l, p[i]); r = max(r, p[i]);
        }
        int ans1 = 0, ans2;
        int right = INT_MIN;
        for (int i = 1; i <= n; i++)
            if (car[i].v > v && car[i].d <= r) {
                ans1++;
            }
        bool flag = false;
        for (int i = 1; i <= n; i++)
            if (car[i].v > v && car[i].d <= r) {
                flag = true;
                break;
            }
        ans2 = flag ? (m - 1) : m;

        printf("%d %d\n", ans1, ans2);
    }
    return 0;
}

